package com.zhiyou100.action;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyou100.entity.Source;
import com.zhiyou100.service.SourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * 资源 分页测试
 *
 * @author yang
 * @version 1.0.0
 * @date 2020-08-28 09:56
 */
@Controller
@RequestMapping("/source")
public class SourceAction {
    private SourceService sourceService;

    @Autowired
    public void setSourceService(SourceService sourceService) {
        this.sourceService = sourceService;
    }

    @RequestMapping("/list.action")
    public String listSource(Model model,
                             @RequestParam(defaultValue = "1",  value = "pageNo") Integer pageNo
    ) {
        // 每页显示的记录数
        int pageSize = 10;

        // 分页查询
        PageHelper.startPage(pageNo, pageSize);

        // 获取所有的信息
        final List<Source> list = sourceService.list();

        // 使用 PageInfo<Source> 结果进行封装
        final PageInfo<Source> pageInfo = new PageInfo<>(list);
        model.addAttribute("pageInfo", pageInfo);
        return "view/source/list";
    }


}
